import importlib
import os
from lib.conf import global_settings


class Settings:
    def __init__(self):
        # 获取默认配置
        default_config = vars(global_settings)
        for i in default_config:
            if i.isupper():
                setattr(self, i, default_config[i])

        # 获取用户配置
        try:
            user_settings = os.environ['USER_SETTINGS']
            settings_module = importlib.import_module(user_settings)
        except Exception:
            settings_module = importlib.import_module('config.settings')
        user_config = vars(settings_module)
        for i in user_config:
            if i.isupper():
                setattr(self, i, user_config[i])


settings = Settings()
